Add shift-clicking to extend the selection. (Roughly based on patch from
authorOwen Taylor <otaylor@redhat.com>
Sat, 3 Mar 2001 21:03:52 +0000 (21:03 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Sat, 3 Mar 2001 21:03:52 +0000 (21:03 +0000)
Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>

* gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
to extend the selection. (Roughly based on patch
from Jay Cox, #50939)

* gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
to properly handle previous GDK_BUTTON_PRESS.
(Patch from Jay Cox, #50938)

* gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
'\0' back along with the deleted text. (#51148)

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkentry.c

index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 27b701c63e24289dc509365e851ece7e91c5cbd7..9c25cb17249a8106a557a16baa0686f3e8e6cf88 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar  3 15:39:49 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Add shift-clicking
+       to extend the selection. (Roughly based on patch
+       from Jay Cox, #50939)
+
+       * gtk/gtkentry.c (gtk_entry_button_press): Fix triple-clicking
+       to properly handle previous GDK_BUTTON_PRESS. 
+       (Patch from Jay Cox, #50938)
+
+       * gtk/gtkentry.c (gtk_entry_real_delete_text): Move the
+       '\0' back along with the deleted text. (#51148)
+
 Mon Jan 22 14:31:29 2001  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkevents-x11.c (gdk_event_translate): Unshift
index 83ae8285cce3c1cf43ad1c34d71a0bba42181a4e..78eb75c8c7868d73455f739a0d47cf802970f2cc 100644 (file)
@@ -1162,11 +1162,72 @@ gtk_entry_button_press (GtkWidget      *widget,
     
   if (event->button == 1)
     {
-      switch (event->type)
+      gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
+      
+      if (event->state & GDK_SHIFT_MASK)
+       {
+         if (!have_selection) /* select from the current position to the clicked position */
+           sel_start = sel_end = entry->current_pos;
+         
+         if (tmp_pos > sel_start && tmp_pos < sel_end)
+           {
+             /* Truncate current selection */
+             entry->current_pos = tmp_pos;
+           }
+         else
+           {
+             gboolean extend_to_left;
+             gint start, end;
+
+             /* Figure out what click selects and extend current selection */
+             switch (event->type)
+               {
+               case GDK_BUTTON_PRESS:
+                 entry->current_pos = entry->selection_bound = tmp_pos;
+                 break;
+                 
+               case GDK_2BUTTON_PRESS:
+                 gtk_entry_select_word (entry);
+                 break;
+                 
+               case GDK_3BUTTON_PRESS:
+                 gtk_entry_select_line (entry);
+                 break;
+
+               default:
+                 break;
+               }
+
+             start = MIN (entry->current_pos, entry->selection_bound);
+             start = MIN (sel_start, start);
+             
+             end = MAX (entry->current_pos, entry->selection_bound);
+             end = MAX (sel_end, end);
+
+             if (tmp_pos == sel_start || tmp_pos == sel_end)
+               extend_to_left = (tmp_pos == start);
+             else
+               extend_to_left = (end == sel_end);
+             
+             if (extend_to_left)
+               {
+                 entry->selection_bound = end;
+                 entry->current_pos = start;
+               }
+             else
+               {
+                 entry->selection_bound = start;
+                 entry->current_pos = end;
+               }
+           }
+         
+         gtk_entry_recompute (entry);
+       }
+      else /* no shift key */
+       switch (event->type)
        {
        case GDK_BUTTON_PRESS:
-         if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end) &&
-             tmp_pos >= sel_start && tmp_pos <= sel_end)
+         if (have_selection && tmp_pos >= sel_start && tmp_pos <= sel_end)
            {
              /* Click inside the selection - we'll either start a drag, or
               * clear the selection
@@ -1188,11 +1249,22 @@ gtk_entry_button_press (GtkWidget      *widget,
          
          break;
 
        case GDK_2BUTTON_PRESS:
+         /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before 
+          * receiving a GDK_2BUTTON_PRESS so we need to reset
+          * entry->in_drag which may have been set above
+           */
+         entry->in_drag = FALSE;
          gtk_entry_select_word (entry);
          break;
-
+       
        case GDK_3BUTTON_PRESS:
+         /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
+          * receiving a GDK_3BUTTON_PRESS so we need to reset
+          * entry->in_drag which may have been set above
+          */
+         entry->in_drag = FALSE;
          gtk_entry_select_line (entry);
          break;
 
@@ -1678,7 +1750,7 @@ gtk_entry_real_delete_text (GtkEntry *entry,
       gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
       gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
 
-      g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes - end_index);
+      g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
       entry->text_length -= (end_pos - start_pos);
       entry->n_bytes -= (end_index - start_index);
       
@@ -2974,7 +3046,7 @@ append_action_signal (GtkEntry     *entry,
 
   gtk_object_set_data (GTK_OBJECT (menuitem), "gtk-signal", (char *)signal);
   gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
-                     activate_cb, entry);
+                     GTK_SIGNAL_FUNC (activate_cb), entry);
 
   gtk_widget_show (menuitem);
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);